<template>
    <div  class="returnOrder-container">
        <!-- 查询表单 -->
        <el-form :inline="true">
            <el-form-item>
                <el-autocomplete
                    v-model="searchObj.frmid"
                    :trigger-on-focus="false"
                    class="inline-input"
                    placeholder="归还单号"
                    value-key="frmid" />
            </el-form-item>
            <el-form-item>
                <el-autocomplete
                v-model="searchObj.fename"
                :trigger-on-focus="false"
                class="inline-input"
                placeholder="归还人"
                value-key="fename" />
            </el-form-item>
            <el-form-item>
                <el-select v-model="searchObj.famstatus" clearable placeholder="归还状态">
                    <el-option
                    v-for="item in status"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-date-picker
                v-model="searchObj.searchStartDate"
                type="date"
                placeholder="选择日期">
                </el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-date-picker
                v-model="searchObj.searchEndDate"
                type="date"
                placeholder="-">
                </el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="fetchData()">查询</el-button>
                <el-button type="default" @click="resetData()">清空</el-button>
            </el-form-item>
        </el-form>
        
        <el-button type="primary" @click.native="vueCreate">创建归还单</el-button>
        <el-button type="primary" @click.native="vueCreate">Excel导入</el-button>
        <el-button type="primary" @click.native="vueCreate">Excel导出</el-button>
        <returnorderinfo v-if="dialogFormVisible" :dialogFormVisible="dialogFormVisible"  :updateOrCreate="updateOrCreate" :editReturnOrder="editReturnOrder" 
         @closepop="closepop" />
        <!-- 表单部分 -->
        <el-table
            :data="returnOrderList"
            style="width: 100%"
        >
            <el-table-column
                prop="frmid"
                label="归还单号"
                width="100"
                sortable
                />
            <el-table-column
                prop="fename"
                label="归还人"
                width="150"
                sortable
                />
            <el-table-column
                prop="fwhname"
                label="归还仓库"
                width="200"
                sortable
                />
            <el-table-column
                prop="frmdate"
                label="归还日期"
                width="100"
                :formatter="dateFormat"
                sortable
                />
            <el-table-column label="归还状态" width="100" prop="frmstatus" sortable>
                <template slot-scope="scope">
                    <el-tag type="warning" effect="dark" v-if="scope.row.famstatus==0">归还中</el-tag>
                    <el-tag type="danger" effect="dark" v-else-if="scope.row.famstatus==1">归还完成</el-tag>
                    <el-tag type="danger" effect="dark" v-else>归还中</el-tag>
                </template>
            </el-table-column>
            <el-table-column
                prop="frmmemo"
                label="备注"
                width="200"
                sortable
                />
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button type="primary" size="big" @click="vueDelete(scope.row.frmid)">删除</el-button>
                    <el-button type="primary" size="big"  @click="vueEdit(scope.row)">编辑</el-button>
                    <el-button type="primary" size="big"  @click="vueEdit(scope.row)">确认</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[10, 50, 100, 200]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="200">
      </el-pagination>
    </div>
</template>
<script>
import moment from 'moment'
import { getReturnOrderList, deleteReturnOrder } from '@/api/returnOrder'
import returnorderinfo from '@/views/acquisitionManagement/giveback/components/ReturnOrderInfo'


export default {
    components: {
        returnorderinfo
    },
    data () {
        return {
            returnOrderList: {},
            searchObj: {},
            dialogFormVisible: false,
            /*true 代表更新，false代表创建*/
            updateOrCreate: false,
            editReturnOrder: {},
            status: [{id: '0',name: '归还中'},{id: '1', name: '归还完成'}]
            
        }
    },
    created() {
        this.fetchData()
    },
    methods: {
        // 事件格式化 利用momeent 模块 npm install moment
        dateFormat: function(row,column) {
            var date = row[column.property]
            if (date == undefined) {
                return ""
            }
            return moment(date).format("YYYY-MM-DD")
        },
        vueCreate() {
            this.dialogFormVisible=true
            this.updateOrCreate=false
        },
        vueEdit(row) {
            this.dialogFormVisible=true
            this.updateOrCreate=true
            this.editReturnOrder=row
        },
        vueReset() {
            this.dialogFormVisible=false
            this.updateOrCreate=false
            this.editReturnOrder={}
        },
        vueDelete(frmid) {
            this.$confirm('此操作将永久删除，受否继续？','提示',{
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                deleteReturnOrder(frmid).then(response => {
                    this.fetchData()
                    this.$message({
                        type: 'success',
                        message: '删除成功'
                    })
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                })
            })
        },
        fetchData() {
            getReturnOrderList(this.searchObj).then(response => {
                this.returnOrderList = response.data.returnOrderList
            })
        },
        resetData() {
            this.searchObj = {}
        }
    }

}
</script>
<style lang="scss" scoped>
    .returnOrder-container {
      margin: 10px 50px 0;
      overflow: hidden;
    }
</style>